package com.chinasoft.advice;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.Random;

@Component
@Aspect
public class Test1wAdvice {
    @Autowired
    Random random;
    @Around("pt()")
    public Object test1wExec(ProceedingJoinPoint pjp) throws Throwable{
        System.out.println("在方法执行前");
        //取系统事件
        long start = System.currentTimeMillis();
        //执行目标方法1w次
        Object ret = null;
        Object[] args = pjp.getArgs();//对象数组是她的参数,


        for(int i=0;i<100;i++) {
            //让id的参数 0 -9999
            args[0] = random.nextInt(100);
            args[1] = 18;
            System.out.println(args[0]);
            ret = pjp.proceed(args);
            System.out.println(ret);
        }
        //取系统时间
        long end = System.currentTimeMillis();
        //计算1w次的执行时间
        System.out.println("小号的时间是"+ (end - start)/1000+"秒");
        System.out.println("在方法执行后");
        return ret;
    }
    @Pointcut("execution(* com.chinasoft.service.BrandService.getOneBrand(..))")
    private void pt() {
        // null;
    }
}

